<template>
  <el-dialog
    :visible="dialogVisible "
    width="400px"
    :title=ruleForm.title
    append-to-body
    :before-close="handleClose"
    @closed="handleClose"
    :close-on-click-modal="false"
  >
    <div class="box">
      <el-form
        ref="ruleForm"
        size="small"
        :model="ruleForm"
        label-width="120px"
      >
        <el-row :gutter="10">
          <el-col :span="24">
            <el-form-item
              label="合同价款"
              prop="leasingPrice"
            >
              <el-input
                v-model="ruleForm.leasingPrice"
                placeholder="请输入标题"
                disabled
                style="width: 100%;"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item
              label="比例"
              prop="calculator"
            >
            <el-select v-model="ruleForm.calculator" placeholder="请选择" :style="{width: '100%'}">
              <el-option
                v-for="item in ratio_calculator"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            </el-form-item>

          </el-col>
        </el-row>
      </el-form>
    </div>
    <div
      slot="footer"
      class="dialog-footer"
    >
      <el-button
        type="primary"
        @click="submitForm"
        :loading="loading"
      >确 定</el-button>
      <el-button @click="handleClose">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  dicts: ["ratio_calculator"],
  data() {
    return {
      dialogVisible: false,
      showDialog: false,
      loading: false,
      ruleForm: {
        leasingPrice: '',//合同价款
        calculator: '',//比例
        money:'',
        text:'',
      },
      ratio_calculator: [],
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    async sync(row) {
      this.ratio_calculator = this.dict.type.ratio_calculator
      this.dialogVisible = true;
      this.ruleForm = {
        leasingPrice: row.leasingPrice,
        title: row.title,
        money:'',
        text:row.text,
      }
    },
    submitForm() {
      if(this.ruleForm.calculator == '' || this.ruleForm.calculator == undefined ||this.ruleForm.calculator == null){
        this.$message.error('请先选择比例')
      }else{
        this.loading = true
        this.ruleForm.money = this.ruleForm.leasingPrice*(this.ruleForm.calculator/100)
        this.$message.success("操作成功")
        this.handleClose()
        this.$emit('ok',this.ruleForm)
      }
    },
    handleClose() {
      this.dialogVisible = false;
      this.loading = false
    },
  }
}
</script>

<style lang="scss" scoped>
</style>
